package fem2.element.crack_sda;

import inf.jlinalg.Array1DMatrix;
import inf.jlinalg.BLAM;
import inf.jlinalg.IMatrix;
import fem2.MaterialModel;
import fem2.MeshPart;
import fem2.material.cohesive_law.CohesiveLaw;

public class KOSConstantJumpElement extends SOSConstantJumpElement {

	public KOSConstantJumpElement(MeshPart mp, MaterialModel mm, CohesiveLaw cohesiveLaw) {
		super(mp, mm, cohesiveLaw);
		enforce_orthogonal_condition = false;
	}

	@Override
	protected void computeEnhancedStrainOperator(MeshPart mp, IMatrix g, double... xi) {
		int dim = mp.getDimension();
		int nn = mp.countModes();
		int ntrs = dim * (dim + 1) / 2;
		BLAM.zero(g);
		Array1DMatrix B = Array1DMatrix.createColumnMajor(ntrs, dim * nn);
		computeB(mp, B, xi);
		if (dim == 2) {
			for (int i = 0; i < posNodes.length; i++) {
				int shift = dim * posNodes[i];
				g.add(0, 0, -B.get(0, shift));
				g.add(1, 1, -B.get(1, 1 + shift));
				g.add(2, 0, -B.get(2, shift));
				g.add(2, 1, -B.get(2, 1 + shift));
			}
		} else if (dim == 3) {
			/*
			 * TODO
			 */
		}
	}
}
